tinymce.PluginManager.add("bdmap", function (editor, url) {
  var pluginName = "插入百度地图";
  var baseURL = tinymce.baseURL;
  var iframe1 = baseURL + "/plugins/bdmap/map.html";
  var bdmap_width = function (editor) {
    return editor.getParam("bdmap_width", 662);
  };
  var bdmap_height = function (editor) {
    return editor.getParam("bdmap_height", 422);
  };
  window.tinymceLng = "";
  window.tinymceLat = "";
  var openDialog = function () {
    return editor.windowManager.openUrl({
      title: pluginName,
      size: "large",
      //width: 800,
      //height: 500,
      url: iframe1,
      buttons: [
        {
          type: "cancel",
          text: "Close",
        },
        {
          type: "custom",
          text: "Save",
          name: "save",
          primary: true,
        },
      ],
      onAction: function (api, details) {
        var html = "";
        switch (details.name) {
          case "save":
            html =
              '<iframe src="' +
              baseURL +
              "/plugins/bdmap/bd.html?center=" +
              tinymceLng +
              "%2C" +
              tinymceLat +
              "&zoom=14&width=" +
              (bdmap_width(editor) - 2) +
              "&height=" +
              (bdmap_height(editor) - 2) +
              '" frameborder="0" style="width:' +
              bdmap_width(editor) +
              "px;height:" +
              bdmap_height(editor) +
              'px;">';
            editor.insertContent(html);
            api.close();
            break;
          default:
            break;
        }
      },
    });
  };

  editor.ui.registry.getAll().icons.bdmap ||
    editor.ui.registry.addIcon(
      "bdmap",
      '<svg t="1610176243474" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="949" width="24" height="24"><path d="M605.234375 692.140625c45.984375-9.703125 39.65625-64.546875 38.390625-76.78125-2.109375-18.5625-24.046875-50.625-53.578125-48.09375-37.125 3.375-42.609375 56.953125-42.609375 56.953125-5.0625 24.890625 11.8125 77.625 57.796875 67.921875z m48.515625 95.34375c-1.265625 3.796875-4.21875 13.5-1.6875 22.359375 5.0625 19.40625 21.9375 20.25 21.9375 20.25h24.046875v-58.640625H672.3125c-11.390625 2.953125-17.296875 12.234375-18.5625 16.03125z m36.703125-187.3125c25.3125 0 45.984375-29.109375 45.984375-65.390625 0-35.859375-20.25-64.96875-45.984375-64.96875-25.3125 0-45.984375 29.109375-45.984375 64.96875 0 36.28125 20.671875 65.390625 45.984375 65.390625z m108.84375 4.21875c33.75 4.21875 55.6875-31.640625 59.90625-59.0625s-17.296875-59.0625-41.34375-64.546875c-24.046875-5.484375-54 32.90625-56.53125 58.21875-3.375 30.375 4.21875 61.171875 37.96875 65.390625z m83.109375 161.15625s-52.3125-40.5-83.109375-84.375c-41.34375-64.546875-100.40625-38.390625-120.234375-5.484375-19.40625 32.90625-50.203125 53.578125-54.421875 59.0625-4.21875 5.484375-63.28125 37.125-50.203125 95.34375 13.078125 57.796875 59.0625 56.953125 59.0625 56.953125s33.75 3.375 72.984375-5.484375 72.984375 2.109375 72.984375 2.109375 91.546875 30.796875 116.859375-28.265625c25.3125-59.484375-13.921875-89.859375-13.921875-89.859375z m-156.9375 87.75h-59.484375c-25.734375-5.0625-35.859375-22.78125-37.125-25.734375-1.265625-2.953125-8.4375-17.296875-4.640625-41.34375 10.96875-35.859375 43.03125-38.390625 43.03125-38.390625h31.640625v-38.8125l27 0.421875-0.421875 143.859375z m110.953125-0.421875h-68.765625c-26.578125-6.75-27.84375-25.734375-27.84375-25.734375v-75.9375l27.84375-0.421875v68.34375c1.6875 7.171875 10.546875 8.4375 10.546875 8.4375h28.265625v-76.359375h29.53125l0.421875 101.671875z m97.453125-202.5c0-13.078125-10.96875-52.734375-51.046875-52.734375-40.5 0-45.984375 37.125-45.984375 63.703125 0 24.890625 2.109375 60.328125 52.3125 59.0625 50.203125-0.84375 44.71875-56.953125 44.71875-70.03125zM465.171875 736.015625c4.21875 8.859375 10.546875 16.03125 18.984375 21.515625 8.4375 5.0625 17.71875 8.015625 27.84375 8.015625s18.984375-2.53125 27.84375-8.015625c8.4375-5.0625 15.1875-12.234375 19.40625-21.515625l3.375-7.171875c-12.65625-5.0625-24.46875-13.5-33.75-24.890625-21.9375-26.578125-27.421875-62.015625-23.203125-86.0625 3.796875-32.90625 24.890625-87.75 80.578125-92.8125 2.109375 0 4.640625-0.421875 6.75-0.421875 3.375 0 6.328125 0 9.28125 0.421875 4.21875-55.265625 41.34375-97.453125 88.171875-97.453125 4.640625 0 8.859375 0.84375 13.078125 1.6875l5.90625-12.234375c8.859375-19.40625 13.5-43.875 13.5-73.828125 0-58.21875-20.671875-108-61.59375-148.921875C620 152.984375 570.21875 132.3125 512 132.3125s-108 20.671875-148.921875 61.59375C321.734375 235.25 301.0625 285.03125 301.0625 343.25c0 29.953125 4.640625 54.421875 13.5 73.828125l150.609375 318.9375zM437.328125 268.578125C458 247.90625 482.890625 237.78125 512 237.78125c29.109375 0 54 10.125 74.671875 30.796875 20.671875 20.671875 30.796875 45.5625 30.796875 74.671875s-10.125 54-30.796875 74.671875c-20.671875 20.671875-45.5625 30.796875-74.671875 30.796875s-54-10.125-74.671875-30.796875C416.65625 397.25 406.53125 372.359375 406.53125 343.25c0-29.109375 10.125-54 30.796875-74.671875zM558.40625 891.6875H90.125l168.75-253.125h113.484375l19.828125 42.1875H281.234375l-112.640625 168.75h367.875c5.484375 17.296875 13.078125 31.21875 21.9375 42.1875z" fill="#222f3e" p-id="950"></path></svg>'
    );

  editor.ui.registry.addButton("bdmap", {
    icon: "bdmap",
    tooltip: pluginName,
    onAction: function () {
      openDialog();
    },
  });
  editor.ui.registry.addMenuItem("bdmap", {
    text: pluginName,
    onAction: function () {
      openDialog();
    },
  });
  return {
    getMetadata: function () {
      return {
        name: pluginName,
        url: "http://tinymce.ax-z.cn/more-plugins/bdmap.php",
      };
    },
  };
});
